package co.yixiang.modules.shop.rest;


import co.yixiang.aop.log.Log;
import co.yixiang.modules.shop.domain.YxStoreBrand;
import co.yixiang.modules.shop.domain.YxStorePlace;
import co.yixiang.modules.shop.service.YxStorePlaceService;
import co.yixiang.modules.shop.service.dto.YxStoreBrandQueryCriteria;
import co.yixiang.modules.shop.service.dto.YxStorePlaceQueryCriteria;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author zengqibin
 * @date 2020/8/12
 */
@Api(tags = "场地管理")
@RestController
@RequestMapping("/api/yxStorePlace")
public class YxStorePlaceController {


    @Autowired
    private YxStorePlaceService yxStorePlaceService;

    @GetMapping
    @Log("查询产地")
    @ApiOperation("查询场地")
    public ResponseEntity<Object> getYxStoreBrands(YxStorePlaceQueryCriteria criteria, Pageable pageable){
        return new ResponseEntity<>(yxStorePlaceService.queryAll(criteria,pageable), HttpStatus.OK);
    }


    @PostMapping
    @Log("新增产地")
    @ApiOperation("新增产地")
    public ResponseEntity<Object> create(@Validated @RequestBody YxStorePlace resources){
        return new ResponseEntity<>(yxStorePlaceService.create(resources),HttpStatus.CREATED);
    }

    @PutMapping
    @Log("修改产地")
    @ApiOperation("修改产地")
    public ResponseEntity<Object> update(@Validated @RequestBody YxStorePlace resources){
        yxStorePlaceService.update(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @Log("删除产地")
    @ApiOperation("删除产地")
    @DeleteMapping
    public ResponseEntity<Object> deleteAll(@RequestBody Integer[] ids) {
        yxStorePlaceService.deleteAll(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }


    @Log("导出数据")
    @ApiOperation("导出数据")
    @GetMapping(value = "/download")
    public void download(HttpServletResponse response, YxStorePlaceQueryCriteria criteria) throws IOException {
        yxStorePlaceService.download(yxStorePlaceService.queryAll(criteria), response);
    }
}
